import Mock from 'mockjs2'
import { builder, getQueryParameters,getBody } from '../util'

const docList = options => {
  let query = getQueryParameters(options)
  console.log('query', query)
  let space = query.spaceId
  let data = [
  {
    "id": 1,
    "spaceId": 1,
    "parentId": 0,
    "title": "1、Java基础知识"
  },
  {
    "id": 2,
    "spaceId": 1,
    "parentId": 1,
    "title": "1、Java语言"
  },
  {
    "id": 3,
    "spaceId": 1,
    "parentId": 1,
    "title": "2、java框架"
  },
  {
    "id": 4,
    "spaceId": 1,
    "parentId": 1,
    "title": "3、jvm虚拟机"
  },
  {
    "id": 5,
    "spaceId": 1,
    "parentId": 41,
    "title": "2、数据库"
  },
  {
    "id": 6,
    "spaceId": 1,
    "parentId": 5,
    "title": "1、关系型数据库"
  },
  {
    "id": 7,
    "spaceId": 1,
    "parentId": 5,
    "title": "2、文档型数据库"
  },
  {
    "id": 8,
    "spaceId": 1,
    "parentId": 5,
    "title": "3、其它类型数据库"
  },
  {
    "id": 9,
    "spaceId": 1,
    "parentId": 41,
    "title": "3、消息队列"
  },
  {
    "id": 10,
    "spaceId": 1,
    "parentId": 9,
    "title": "1、RabbitMQ消息队列"
  },
  {
    "id": 11,
    "spaceId": 1,
    "parentId": 9,
    "title": "2、RocketMQ消息队列"
  },
  {
    "id": 12,
    "spaceId": 1,
    "parentId": 9,
    "title": "3、Kafka"
  },
  {
    "id": 13,
    "spaceId": 1,
    "parentId": 0,
    "title": "2、数据结构与常用算法"
  },
  {
    "id": 15,
    "spaceId": 1,
    "parentId": 13,
    "title": "1、常用数据结构"
  },
  {
    "id": 16,
    "spaceId": 1,
    "parentId": 13,
    "title": "2、常用算法"
  },
  {
    "id": 17,
    "spaceId": 1,
    "parentId": 1,
    "title": "4、java常用工具/命令"
  },
  {
    "id": 18,
    "spaceId": 1,
    "parentId": 0,
    "title": "3、操作系统"
  },
  {
    "id": 19,
    "spaceId": 1,
    "parentId": 18,
    "title": "1、Linux系统"
  },
  {
    "id": 20,
    "spaceId": 1,
    "parentId": 18,
    "title": "2、Windows系统"
  },
  {
    "id": 21,
    "spaceId": 1,
    "parentId": 0,
    "title": "4、微服务"
  },
  {
    "id": 22,
    "spaceId": 1,
    "parentId": 21,
    "title": "1、注册中心"
  },
  {
    "id": 23,
    "spaceId": 1,
    "parentId": 21,
    "title": "2、配置中心"
  },
  {
    "id": 24,
    "spaceId": 1,
    "parentId": 0,
    "title": "5、容器"
  },
  {
    "id": 25,
    "spaceId": 1,
    "parentId": 24,
    "title": "1、docker基础"
  },
  {
    "id": 26,
    "spaceId": 1,
    "parentId": 41,
    "title": "2、k8s"
  },
  {
    "id": 27,
    "spaceId": 1,
    "parentId": 3,
    "title": "1、spring全家桶"
  },
  {
    "id": 28,
    "spaceId": 1,
    "parentId": 27,
    "title": "1、spring"
  },
  {
    "id": 29,
    "spaceId": 1,
    "parentId": 27,
    "title": "2、spring MVC"
  },
  {
    "id": 30,
    "spaceId": 1,
    "parentId": 27,
    "title": "3、spring boot"
  },
  {
    "id": 31,
    "spaceId": 1,
    "parentId": 21,
    "title": "3、网关"
  },
  {
    "id": 32,
    "spaceId": 1,
    "parentId": 21,
    "title": "4、spring-cloud"
  },
  {
    "id": 33,
    "spaceId": 1,
    "parentId": 3,
    "title": "2、mybatis"
  },
  {
    "id": 34,
    "spaceId": 1,
    "parentId": 2,
    "title": "1、String、StringBuilder、StringBuffer"
  },
  {
    "id": 35,
    "spaceId": 1,
    "parentId": 2,
    "title": "2、Java集合框架"
  },
  {
    "id": 36,
    "spaceId": 1,
    "parentId": 35,
    "title": "1、Collection"
  },
  {
    "id": 37,
    "spaceId": 1,
    "parentId": 35,
    "title": "2、Collections(集合代理类)"
  },
  {
    "id": 38,
    "spaceId": 1,
    "parentId": 36,
    "title": "1、List(列表集合)"
  },
  {
    "id": 39,
    "spaceId": 1,
    "parentId": 36,
    "title": "2、Set集合"
  },
  {
    "id": 40,
    "spaceId": 1,
    "parentId": 35,
    "title": "3、Map集合"
  },
  {
    "id": 41,
    "spaceId": 1,
    "parentId": 0,
    "title": "6、中间件"
  }
]
  return builder(data)
}

const getDoc = options => {
	let query = getQueryParameters(options)
  console.log('query', query)
  const id = query.id
  const data = {
    id: id,
	spaceId: 1,
	title: '文档1',
	content: '<p>你人呢让你让你让你让你让你让内容内容内容内容内容内容内容内容内容内容</p>',
	addTime: new Date().getTime()
  }
  return builder(data)
}

const saveDoc = options => {
	console.log('saveDoc',options)
	return builder(null)
}

const modifyDoc = options => {
	const body = getBody(options)
	console.log('modifyDoc body',body)
	return builder({
		id: body.id
	})
}

const removeDoc = options => {
	const body = getBody(options)
	console.log('removeDoc body',body)
	return builder(null)
}

Mock.mock(/\/api\/doc\/get/, 'get', getDoc)
Mock.mock(/\/api\/doc\/list/, 'get', docList)
Mock.mock(/\/api\/doc\/save/, 'post', saveDoc)
Mock.mock(/\/api\/doc\/modify/, 'post', modifyDoc)
Mock.mock(/\/api\/doc\/remove/, 'post', removeDoc)

